package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {
    /*
    * 统计关联菜品数量
    * */
    Integer dishIdCount(List<Long> ids);
    /*
    * 插入套餐关联餐品
    * */
    void insert(List<SetmealDish> setmealDishes);

    /*
    * 根据套餐id查询菜品
    * */
    @Select("SELECT * FROM setmeal_dish WHERE setmeal_id = #{setmealId}")
    List<SetmealDish> selectBySetmealId(Long setmealId);
    /*
    * 根据套餐id删除关联菜品
    * */
    @Delete("DELETE FROM setmeal_dish WHERE setmeal_id = #{setmealId}")
    void deleteBySetmealId(Long setmealId);

    @Select("SELECT count(dish.id) FROM dish,setmeal_dish \n" +
            "WHERE dish.id = setmeal_dish.dish_id " +
            "AND dish.status = #{status} " +
            "AND setmeal_dish.setmeal_id =#{setmealId}")
    Integer selectCloseStatusCount(Long setmealId, Integer status);


    @Select("SELECT dish.name name,copies,image,description FROM dish,setmeal_dish " +
            "WHERE setmeal_id = #{setmealId} AND dish_id = dish.id")
    List<DishItemVO> selectBySetmealIdInfo(Long setmealId);
}
